package com.example.shardingsphere.controller.emums;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter  //生成一个 get 方法
@AllArgsConstructor
public enum UserIdentityEnum {

    SUPER_ADMIN(1,"super_admin"),

    NORMAL(2,"user"),

    ADMIN(3,"admin");



    private final Integer code;
    private final String massage;


    /**
     * 根据 传进来的字符串  identity 进行枚举判断
     * @param name
     * @return
     */
    public static UserIdentityEnum forName(String name){
        for (UserIdentityEnum userIdentityEnum : UserIdentityEnum.values()){
            //equalsIgnoreCase(name) 用于忽略大小写地比较枚举常量的名称和传入的字符串 name 是否相等。
            if (userIdentityEnum.name().equalsIgnoreCase(name)){
                return userIdentityEnum;
            }
        }
        return null;
    }
    public static String getIdentityName(Integer code){
        for (UserIdentityEnum userIdentityEnum : UserIdentityEnum.values()){
            if (userIdentityEnum.getCode().equals(code)){
                return userIdentityEnum.name();
            }
        }
        return null;
    }
}
